/*
 * Copyright (c) 2010-2011 Plugger Antonio Begue Ponce. All Rights Reserved.
 *
 * This file is part of Plugger Framework.
 *
 *  Plugger Framework is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License version 3 as published by
 *  the Free Software Foundation.
 *
 *  Plugger Framework is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Plugger Framework.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.plugger.ui.viewmodel;

import java.awt.Component;
import javax.swing.JMenuBar;
import org.plugger.ui.base.*;

/**
 * This abstract class defines a layout view controller.
 *
 * @author "Antonio Begue"
 * @version $Revision: 1.0 $
 */
public abstract class LayoutViewModel extends ViewModelBase implements ILayoutViewModel {
    private ILayoutView view;
    private LayoutViewModel contentLayout;

    public LayoutViewModel(ILayoutView view) {
        super(view);
        this.view = view;
        //this.view.setDate(new DateHelper("MMMM dd, yyyy").getDate());
    }

    public abstract void startUp();
    public abstract void shutDown();
//    public abstract void setContent(Component content);

    public void setControl(Component control) {
        view.setControl(control);
    }

    public void setControl(Component control, int top, int left) {
        view.setControl(control, top, left);
    }

    public void setContent(Component control) {
        if (getContentLayout() == null) {
            setControl(control);
            view.setTitle(((IView)control).getTitle());
        } else {
            getContentLayout().setContent(control);
        }
    }

    public void setContent(Component control, int top, int left) {
        if (getContentLayout() == null) {
            setControl(control, top, left);
        } else {
            getContentLayout().setContent(control, top, left);
        }
    }

    public ILayoutView getLayoutView() {
        return this.view;
    }

    public void setMenu(JMenuBar menu) {
        view.setMenu(menu);
    }

    /**
     * @return the contentLayout
     */
    public LayoutViewModel getContentLayout() {
        return contentLayout;
    }

    /**
     * @param contentLayout the contentLayout to set
     */
    public void setContentLayout(LayoutViewModel contentLayout) {
        this.contentLayout = contentLayout;
    }
}
